package com.kuang.controller;

import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

/**
 * 这个controller 是用来测试 restFul的
 * restFul风格的好处
 * 1、简洁
 * 2、高效 可以有缓存
 * 3、安全，不会暴露变量名
 */
@Controller
@RequestMapping("/restFul")
public class RestFulController {
    //path  localhost:8888/restFul/add/1/2
    @RequestMapping(value = "/add/{a}/{b}",method = RequestMethod.GET)
    public String add(@PathVariable int a, @PathVariable int b, Model model){
        int result = a + b ;
        model.addAttribute("add","结果是"+result);
        return "test";
    }

    //restFul风格还可以让路径相同，但是请求方式（get，post）不同，会走不同的controller
    @RequestMapping(value = "/add/{a}/{b}",method = RequestMethod.POST)
    public String add2(@PathVariable int a, @PathVariable int b, Model model){
        int result = a + b ;
        model.addAttribute("add","结果2是"+result);
        return "test";
    }

}
